function GetQueryString(name)
{
 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
 var r = window.location.search.substr(1).match(reg);
 if(r!=null)return  unescape(r[2]); return null;
}
function getAllMessage() {
	var pageCount= GetQueryString("pageCount") ;
	var limitCount = 10;
		$.ajax({
				type : "POST",
				url : "requestMsgListByPage.action",
				data : {page:pageCount == undefined?1:pageCount,limit:limitCount,blogArticleId:-2},
				dataType : 'json',
				success :function(result) {
					if(result.status != 200){
						alert("无数据");
						return;
					}
					if(result.data.allRow >limitCount){
						setPageParam(result.data);
					}
						var datas = result.data.list;
							var i = 0;
							for (i = 0; i < datas.length; i++) {
								var tr = $("<tr></tr>");
								tr.appendTo($("#messagelist"));
								var id = $("<td width='5%'>" + (i+1)
										+ "</td>");
								var kind = $("<td width='15%'>" + datas[i].formatTime
										+ "</td>");
								var title = $("<td width='15%'>" + datas[i].titile
										+ "</td>");
								var pubdate = $("<td width='12%'>"
										+ datas[i].visitorName + "</td>");
								var author = $("<td width='30%'>"
										+ datas[i].msgContext + "</td>");
								var deal = $("<td width='23%'></td>");
								var check = $("<a class='sj_btn'href='singleMessage.html?id="+datas[i].id+"' >查看</a>");
								var del = $("<a class='del_btn' name='del' data-id='"+datas[i].id+"'onclick='onRemove(this);'>删除</a>");
								
								check.appendTo(deal);
								del.appendTo(deal);
								id.appendTo(tr);
								kind.appendTo(tr);
								title.appendTo(tr);
								pubdate.appendTo(tr);
								author.appendTo(tr);
								deal.appendTo(tr);
							}
				}
			});
	}
function setPageParam(data) {
	var nextPager,
		prePager;
	if(data.hasNextPage){
		nextPager =$("<li class='next'><a href=messageManager.html?pageCount="+(data.currentPage+1)+" >下一页 &rarr;</a></li>");
	}else{
		nextPager =$("<li class='next disabled'><a >下一页 &rarr;</a></li>");
	}
	
	if(data.hasPreviousPage){
		prePager =$("<li class='previous'><a href=messageManager.html?pageCount="+(data.currentPage-1)+" >&larr; 上一页</a></li>");
	}else{
		prePager =$("<li class='previous disabled'><a >&larr; 上一页</a></li>");
	}
	nextPager.appendTo($("#pager"));
	prePager.appendTo($("#pager"));
	
}
var onRemove = function(obj){
	var id=$(obj).attr('data-id');
		$.ajax({
			type : "GET",
			url : "removeMsg.action",
			data : "id=" + id,
			dataType : 'json',
			success : function(result) {
			
				if (result.status == 200) {
					window.location.reload();
				} else {
					alert(result);
				}

			}
			});
};
$(function() {
	// body...
	getAllMessage();
	
});